package com.permission.controller;

import com.permission.dto.request.menu.*;
import com.permission.message.StandardResponse;
import com.permission.service.SysMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @desc: 菜单的基本接口
 * @author: xhs
 * @date: 2021/9/14 14:56
 * @version: JDK 1.8
 */
@Slf4j
@RestController
@RequestMapping("/api/menu")
public class MenuController {

    @Autowired
    private SysMenuService menuService;

    /**
     * 新增菜单接口
     *
     * @param request
     * @param menuRequest
     * @return
     */
    @PostMapping("/insertMenu")
    public StandardResponse<Object> insertMenu(HttpServletRequest request, @Valid @RequestBody InsertMenuRequest menuRequest) {
        log.info("-----------------【新增菜单接口入参 menuJson：{}】--------------", menuRequest.toString());
        return menuService.insertMenu(request, menuRequest);
    }

    /**
     * 编辑菜单接口
     *
     * @param request
     * @param menuRequest
     * @return
     */
    @PostMapping("/updatetMenu")
    public StandardResponse<Object> updatetMenu(HttpServletRequest request, @Valid @RequestBody UpdatetMenuRequest menuRequest) {
        log.info("-----------------【编辑菜单接口接口入参 menuJson：{}】--------------", menuRequest.toString());
        return menuService.updatetMenu(request, menuRequest);
    }

    /**
     * 查询菜单接口
     *
     * @param menuRequest
     * @return
     */
    @PostMapping("/selectMenu")
    public StandardResponse<Object> selectMenu(@Valid @RequestBody SelectMenuRequest menuRequest) {
        log.info("-----------------【查询菜单接口入参 menuRequest：{}】--------------", menuRequest.toString());
        return menuService.selectMenu(menuRequest);
    }

    /**
     * 删除菜单
     *
     * @return
     */
    @PostMapping("/del")
    public StandardResponse<Object> del(@Valid @RequestBody DelMenuRequest menuRequest) {
        log.info("--------删除菜单:{}--------", menuRequest.toString());
        return menuService.del(menuRequest);
    }

    /**
     * 根据Id查询菜单
     *
     * @param menuRequest
     * @return
     */
    @PostMapping("/selectMenuById")
    public StandardResponse<Object> selectMenuById(@Valid @RequestBody SelectMenuByIdRequest menuRequest) {
        log.info("-----------------【查询菜单接口入参 menuRequest：{}】--------------", menuRequest.toString());
        return menuService.selectMenuById(menuRequest);
    }
}
